/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package brisollogic;


/**
 *Get - Set class for User objects.
 * @author monster
 */
public class User {

    private final int userId;
    private final String name;    
    private final Status status;
    private final Credentials cred;

    private User(UserBuilder builder) {
        this.userId = builder.userId;
        this.name = builder.name;                       
        this.status = builder.status;
        this.cred = builder.cred;
    }

    public static class UserBuilder implements Builder<User> {
        //Required parameters
        private final Credentials cred;        
        
        //Optional paraemeters
        private String name = "Unknown";
        private int userId = 0;
        private Status status = User.Status.None;

        public UserBuilder(Credentials cred) {
            this.cred = cred;
        }

        public UserBuilder name(String val) {
            name = val;
            return this;
        }

        public UserBuilder id(int val) {
            userId = val;
            return this;
        }

        public UserBuilder status(Status val) {
            status = val;
            return this;
        }

        public User build() {
            User user = new User(this);
            if (user.name == null) {
                throw new NullPointerException("String name must not be null");
            } else if(user.status == null) {
                throw new NullPointerException("User.Status status must not be null");
            } else if(user.name.isEmpty()) {
                throw new IllegalArgumentException("String name must not be empty");
            }
            return user;
        }
    }

    /**
     * @return the password
     */
    public String getPassword() {
        return cred.getPassword();
    }

    /**
     * Enum for the user status
     */
    public enum Status {

        User, Admin, None;
    }

    /**
     * @return the userId
     */
    public int getUserId() {
        return userId;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @return the email
     */
    public String getEmail() {
        return cred.getEmail();
    }

    /**
     * @return the status
     */
    public Status getStatus() {
        return status;
    }
    
    @Override
    public String toString() {
        return ("UserId " + userId + " Name " + name + " Email " + cred.getEmail() + " Password " + cred.getPassword() + " status " + status);
    }
}
